package com.fdb.efp.esb.service.impl.basicfn;

import com.alibaba.fastjson.JSONObject;
import com.fdb.efp.esb.common.client.resp.EsbRespServiceBean;
import com.fdb.efp.esb.common.constant.EsbBizEnums;
import com.fdb.efp.esb.service.facade.basicfn.FiveLeClaManChangeService;
import com.fdb.basic.framework.core.constant.ESBConstant;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.efp.esb.service.bo.req.basicfn.FiveLeClaManChangeReqBean;
import com.fdb.efp.esb.service.bo.resp.basicfn.FiveLeClaManChangeRespBean;
import com.fdb.efp.esb.service.client.ESBClientFactory;
import com.fdb.efp.esb.service.client.impl.Lhx2ESBBeanCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service("fiveLeClaManChangeService")
public class FiveLeClaManChangeServiceImpl implements FiveLeClaManChangeService {
    private static Logger logger = LoggerFactory.getLogger(FiveLeClaManChangeServiceImpl.class);

    @Override
    public FiveLeClaManChangeRespBean applyFiveLeClaManChange(FiveLeClaManChangeReqBean fiveLeClaManChangeReqBean) throws ESBException {
        logger.info("======>调用五级分类手工变更接口【30220018_01】开始<======");
        FiveLeClaManChangeRespBean fiveLeClaManChangeRespBean = null;
        try {
            EsbRespServiceBean recvBean = ESBClientFactory.buildClient()
                    .withBody(fiveLeClaManChangeReqBean)
                    .withTradeNo(ESBConstant.TRADE_NO_30220018)
                    .withScene(ESBConstant.SECNE_NO_01)
                    .withESBBeanFactory(Lhx2ESBBeanCreator.getINSTANCE())
                    .create()
                    .sendAndReceive();
            if (EsbBizEnums.RetCodeEnum.SUCCESS.VALUE.equals(recvBean.getSysHead().getRetInfArry().get(0).getRetCd())) {
                fiveLeClaManChangeRespBean = new FiveLeClaManChangeRespBean();
                fiveLeClaManChangeRespBean.setRetCd(recvBean.getSysHead().getRetInfArry().get(0).getRetCd());
                fiveLeClaManChangeRespBean.setRetMsg(recvBean.getSysHead().getRetInfArry().get(0).getRetMsg());
            } else {
                throw new ESBException(recvBean.getSysHead().getRetInfArry().get(0).getRetMsg());
            }
            logger.info("调用五级分类手工变更接口【30220018_01】结束，返回信息：" + JSONObject.toJSONString(fiveLeClaManChangeRespBean));
        } catch (Exception e) {
            logger.error("调用五级分类手工变更接口【30220018_01】出现异常：" + e.getMessage());
            throw new ESBException("调用五级分类手工变更接口【30220018_01】出现异常：" + e.getMessage());
        } finally {
            logger.info("======>调用五级分类手工变更接口【30220018_01】结束<======");
        }
        return fiveLeClaManChangeRespBean;
    }
}